//
//  LenderPersonVC.m
//  SelfDrivingTravelling-IOS
//
//  Created by Teplot_01 on 16/8/31.
//  Copyright © 2016年 Teplot_01. All rights reserved.
//

#import "LenderPersonVC.h"
#import "LeaderPersonalInforVC.h"
#import "LenderPersonCell.h"
#import "LeaderActityManVC.h"
#import "LeaderBillManagerVC.h"
#import "LeaderSettingVC.h"
#import "LeaderActityListVC.h"
#import "MyTravelsVC.h"
@interface LenderPersonVC ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation LenderPersonVC
{
    UITableView *_tableView;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [_tableView reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self initLenderPersonTableView];
    //去除多余的分割线
    _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
- (void)initLenderPersonTableView{
    _tableView = [[UITableView alloc]initWithFrame:self.view.frame];
    _tableView.backgroundColor = LighterGrayColor;
    _tableView.scrollEnabled = NO;
    _tableView.dataSource = self;
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
}

#pragma - mark UITabelViewDelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 3;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (section == 0) {
        return 1;
    }
    if (section == 1) {
        return 3;
    }else{
        return 1;
    }
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        LenderPersonCell *cell = [[NSBundle mainBundle]loadNibNamed:@"LenderPersonCell" owner:nil options:nil][0];
        NSString *urlStr = [NSString readToNSDefaultsWithKey:kPhotoUrl];
        [cell.icon sd_setImageWithURL:[NSURL URLWithString:urlStr] placeholderImage:[UIImage imageNamed:@"userIcon"]];
        cell.icon.layer.cornerRadius = 8;
        cell.icon.layer.masksToBounds = YES;
        cell.icon.contentMode = UIViewContentModeScaleAspectFill;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSString *realNameStr = [NSString readToNSDefaultsWithKey:kRealName];
        if ([realNameStr isEqualToString:@""]) {
            cell.realName.text = @"请完善姓名";
            cell.realName.textColor = Orange_Color;
        }else{
            cell.realName.text = [NSString stringWithFormat:@"%@%@",@"姓名:",realNameStr];
        }
        NSString *nickStr = [NSString readToNSDefaultsWithKey:kNickName];
        if ([nickStr isEqualToString:@""]) {
            cell.nickName.text = @"请完善昵称";
            cell.nickName.textColor = Orange_Color;
        }else{
            cell.nickName.text = nickStr;
        }
        cell.idCard.text = [@"身份验证：" stringByAppendingString:[NSString readToNSDefaultsWithKey:kCard]];
        cell.account.text = [@"账户名：" stringByAppendingString:[NSString readToNSDefaultsWithKey:kPhone]];
        return cell;
    }else{
        UITableViewCell *cell = [[UITableViewCell alloc]init];
        //        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        NSArray *titleArr = [[NSArray alloc] initWithObjects:@"活动管理",@"账单管理",@"我的游记",@"设置",nil];
        NSArray *iconArr = [[NSArray alloc] initWithObjects:@"wodeyouji",@"wodezhangdan",@"wodehuodong",@"setting",nil];
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.font = [UIFont systemFontOfSize:15];
        if (indexPath.section == 1) {
            cell.textLabel.text = [titleArr objectAtIndex:indexPath.row];
            cell.imageView.image = [UIImage imageNamed:[iconArr objectAtIndex:indexPath.row]];
        }else{
            cell.textLabel.text = [titleArr objectAtIndex:indexPath.row+3];
            cell.imageView.image = [UIImage imageNamed:[iconArr objectAtIndex:indexPath.row+3]];
        }
        
        return cell;
    }
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    NSInteger index = [tableView indexWithIndexPath:indexPath];
    switch (index) {
        case 0:
        {
            LeaderPersonalInforVC *vc = [[LeaderPersonalInforVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 1:
        {
            LeaderActityListVC *vc = [[LeaderActityListVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 2:
        {
            LeaderBillManagerVC *vc = [[LeaderBillManagerVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 3:
        {
            MyTravelsVC *vc = [[MyTravelsVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
        case 4:
        {
            LeaderSettingVC *vc = [[LeaderSettingVC alloc]init];
            vc.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:vc animated:YES];
        }
            break;
    }
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return 86;
    }else{
        return 40;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    if (section == 0) {
        return 0;
    }
    return 15;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
